package com.hspedu.encap;

public class Account {
    private String name;
    private double balance;
    private String pwd;

    public Account(String name, double balance, String pwd) {
//        this.name = name;
//        this.balance = balance;
//        this.pwd = pwd;
        setBalance(balance);
        setName(name);
        setPwd(pwd);
    }

    //给定一个无参的构造器，就能实现灵活的调用。否则，只能调用有参的构造器的话，就必须得在创建对象的时候就要传参
    public Account() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if(name.length() >= 2 && name.length() <= 4)
            this.name = name;
        else{
            System.out.println("设置的名字不对，需要在（2-4），给定默认名字:无名人");
            this.name = "无名人";
        }
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        if(balance >= 20)
            this.balance = balance;
        else
            System.out.println("余额(必须>20)");
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        if(pwd.length() == 6)
           this.pwd = pwd;
        else{
            System.out.println("密码(必须是六位)，默认为000000");
            this.pwd = "000000";
        }
    }
    //显示信息
    /*public String Info(){
        System.out.println("=========信息为==========");
        return "信息为 names " + name + " age=" + age + " 薪水" + salary;
    }*/
    public void showInfo(){
        System.out.println("=========信息为==========");
        System.out.println("names " + name + " 密码=" + pwd + " balance" + balance);
    }
}
